<script setup lang="ts">
import { ref, watch } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from './hooks'
import { compileScript } from "vue/compiler-sfc";
import { useTranslationLang } from "@/layout/hooks/useTranslationLang";
const { locale } = useTranslationLang();
import { useI18n } from "vue-i18n";
const { t } = useI18n();

const props = withDefaults(defineProps<FormProps>(), {
    formInline: () => ({
        name: "",
        ip: "",
        port: "",
        brand: "",
        note: "",
        moveheight: null,
        model: null,
        movelowheight: null,
        status: null,
        vehicletype: null,
        mapid: null,
        chargingpoint: null,
        stoppoint: null,
        license: "",
        sort: null
    }),
    agvModel: [],
    vehicletype: [],
    mapTypes: [],
    agvBrands: [],
    chargingSelect: [],
    stopSelect: []
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
const agvModel = ref(props.agvModel);
const vehicletype = ref(props.vehicletype);
const mapTypes = ref(props.mapTypes);
const chargingSelect = ref(props.chargingSelect);
const stopSelect = ref(props.stopSelect);
const { switchStyle } = usePublicHooks();

function getRef() {
    return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
    <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="80px"
        :label-position="locale === 'en' ? 'top' : 'right'">
        <el-row :gutter="30">
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.vehicleName')" prop="name">
                    <el-input v-model="newFormInline.name" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.brand')" prop="brand">
                    <el-select v-model="newFormInline.brand" style="width:100%">
                        <el-option v-for="item in agvBrands" :key="item.Code" :label="item.Name" :value="item.Code" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.ipAddress')" prop="ip">
                    <el-input v-model="newFormInline.ip" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.communicationPort')" prop="port">
                    <el-input v-model="newFormInline.port" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.model')" prop="model">
                    <el-select v-model="newFormInline.model" style="width:100%">
                        <el-option v-for="item in agvModel" :key="item.Code" :label="item.Name" :value="item.Code" />
                    </el-select>
                </el-form-item>
            </re-col>
            <!-- <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="车型" prop="vehicletype">
          <el-select v-model="newFormInline.vehicletype" placeholder="请选择车型" style="width:100%">
            <el-option v-for="item in vehicletype" :key="item.Code" :label="item.Name" :value="item.Code" />
          </el-select>
        </el-form-item>
      </re-col> -->

            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.walkingHeight')" prop="moveheight">
                    <el-input-number v-model="newFormInline.moveheight" controls-position="right" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.cargoWalkingHeight')" prop="movelowheight" label-width="120px">
                    <el-input-number v-model="newFormInline.movelowheight" controls-position="right" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.applicableMaps')" prop="mapid">
                    <el-select v-model="newFormInline.mapid" style="width:100%">
                        <el-option v-for="item in mapTypes" :key="item.id" :label="item.name" :value="item.id" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.sort')" prop="sort">
                    <el-input-number v-model="newFormInline.sort" controls-position="right" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.authorizationCode')" prop="license">
                    <el-input v-model="newFormInline.license" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.status')" prop="status">
                    <el-switch v-model="newFormInline.status" inline-prompt :active-value="1" :inactive-value="0"
                        :active-text="t('agvs.enable')" :inactive-text="t('agvs.disable')" :style="switchStyle" />
                </el-form-item>
            </re-col>
            <re-col :value="24" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.chargePoint')" prop="chargingpoint">
                    <el-select v-model="newFormInline.chargingpoint" multiple style="width:100%">
                        <el-option v-for="item in chargingSelect" :key="item.stationid" :label="item.stationname"
                            :value="item.stationid" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="24" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.pointOfNoReturn')" prop="stoppoint">
                    <el-select v-model="newFormInline.stoppoint" multiple style="width:100%">
                        <el-option v-for="item in stopSelect" :key="item.stationid" :label="item.stationname"
                            :value="item.stationid" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="24" :xs="24" :sm="24">
                <el-form-item :label="t('agvs.remarks')" prop="note">
                    <el-input v-model="newFormInline.note" clearable type="textarea" />
                </el-form-item>
            </re-col>
        </el-row>
    </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
    margin-right: 16px;
}
</style>
